package com.servlet;

import com.dao.EmployeeDao;
import com.model.Employee;
import com.dto.PageDTO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/empList")
public class EmpListServlet extends HttpServlet {

     private EmployeeDao employeeDao = new EmployeeDao();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=UTF-8");
        String pageNumberStr = req.getParameter("pageNumber");
        String pageLimitStr = req.getParameter("pageLimit");

        int pageNumber = 1;
        int pageLimit = 5;
        if (pageNumberStr!=null){
            pageNumber = Integer.parseInt(pageNumberStr);
        }
        if (pageLimitStr!=null){
            pageLimit = Integer.parseInt(pageLimitStr);
        }
        PageDTO<Employee> pageDTO = employeeDao.selectList(pageNumber, pageLimit);

        req.setAttribute("pageDTO", pageDTO);

        req.getRequestDispatcher("EmpList.jsp").forward(req, resp);

    }
}
